package org.example.exception;


import org.example.util.JsonResult;
import org.example.util.ResultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(Exception.class)
    public JsonResult sqlException(Throwable e){
        return ResultTool.fail(500, e.getMessage());
    }
    @ExceptionHandler(UserSaveException.class)
    public JsonResult UserSaveException(Throwable e){
     return ResultTool.fail(5001, e.getMessage());
    }
    @ExceptionHandler(UserRemoveException.class)
    public JsonResult UserRemoveException(Throwable e){
        return ResultTool.fail(5002,e.getMessage());
    }
    @ExceptionHandler(UserUpdateException.class)
    public JsonResult UserUpdateException(Throwable e){
        return ResultTool.fail(5003,e.getMessage());
    }
    @ExceptionHandler(PasswordNotExistsException.class)
    public JsonResult PasswordNotExistsException(Throwable e){
        return ResultTool.fail(5004,e.getMessage());
    }
    @ExceptionHandler(NotLoginException.class)
    public JsonResult notLoginException(Throwable e){
        return ResultTool.fail(5091,e.getMessage());
    }

}
